package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.MqLockNet;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.entity.Plmn;

import java.util.List;

/**
 * @author mjy
 * @date 2022/12/29
 * @description
 */
public class SetLockNet implements Sender {


    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqLockNet lockNet = (MqLockNet) mqMessage.getObject();
        List<Plmn> plmns = lockNet.getPlmns();
        String imei = lockNet.getImei();
        String header = "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",")
                .concat(Constants.LOCK_NET).concat(",").concat(lockNet.getCommandNumber()).concat(",")
                .concat(String.valueOf(lockNet.getFlag())).concat(",").concat(String.valueOf(lockNet.getGroupNum()));
        String tail = "#";
        String content="";
        if (plmns!=null&&plmns.size()>0){
            for (Plmn plmn : plmns) {
                String mcc = plmn.getMcc();
                String mnc = plmn.getMnc();
                content += ",".concat(mcc).concat(",").concat(mnc);
            }
        }
        content = header.concat(content).concat(tail);
        Command command = new Command();
        command.setImei(lockNet.getImei());
        command.setContent(content);
        command.setCmd(Constants.LOCK_NET);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setCommandNumber(lockNet.getCommandNumber());
        return command;
    }
}
